//
//  ZanButton.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/2/2.
//  Copyright © 2016年 game. All rights reserved.
//

#import "ZanButton.h"
#import "AppDelegate.h"

@interface ZanButton  ()


@property (nonatomic,strong) AppDelegate *app;

@end

@implementation ZanButton


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.Zanimage.alpha = 1;
        [self addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];
        
        self.app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    }
    return self;
}

-(UIImageView *)Zanimage{
    if (!_Zanimage) {
    
        _Zanimage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, W(self)*0.35, H(self)-10)];
        
        
        [self addSubview:_Zanimage];
    }
    return _Zanimage;
}


-(UILabel *)textLab{
    if (!_textLab) {
        _textLab = [[UILabel alloc]initWithFrame:CGRectMake(Width(_Zanimage)+3, 3, Width(self)-Width(_Zanimage), H(self)-3)];
        _textLab.textAlignment = NSTextAlignmentLeft;
   
        [self addSubview:_textLab];
    }

    return _textLab;
}

-(void)Click:(ZanButton *)button{
    
    if ([self.app.isLogin isEqualToString:@"YES"]) {
        
//        CGRect rect = CGRectMake(5, 5, W(self)*0.35, H(self)-10));
        
//        [UIView animateWithDuration:0.3 animations:^{
//            
//            _Zanimage.transform = CGAffineTransformScale(self.imageView.transform, 1.5, 1.5);
//        } completion:^(BOOL finished) {
//            
//            _Zanimage.transform = CGAffineTransformScale(self.imageView.transform, 1, 1);
//        }];
        
        [self.Zanimage setBounds:CGRectMake(0, 0, 0, 0)];
        [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.2 initialSpringVelocity:5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            
            [self.Zanimage setBounds:CGRectMake(5, 5, W(self)*0.35, H(self)-10)];
        
        } completion:^(BOOL finished) {
            
            NSString *countStr = self.textLab.text;
            NSInteger cout = countStr.integerValue + 1;
            
            self.textLab.text = [NSString stringWithFormat:@"%ld",(long)cout];
            
            self.enabled = NO;//完成后禁用button
            
            [self.deleget LoginClick];
            
        }];

    }else{
        [self.deleget NoLoginClik];
    
    }

}

@end
